<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理后台</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="/favicon.ico" type="image/x-icon" rel="shortcut icon" />
    <!-- Bootstrap 3.3.4 -->
    <link href="/Public/static/Tpshop/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/Public/static/Tpshop/bootstrap/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

    <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/static/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/public/static/admin/css/animate.css" rel="stylesheet">
    <link href="/public/static/admin/css/ratuo.css" rel="stylesheet">
    <link href="/public/static/admin/css/style.css?v=4.0.0" rel="stylesheet">

    <script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/static/admin/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="/public/static/admin/js/common.js"></script>
    <script src="/public/static/admin/js/plugins/layer/layer.min.js"></script>
    <script src="/public/static/admin/js/myAjax.js"></script>
    <script src="/public/static/admin/js/jquery.validate.js"></script>

    <link href="/public/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <script src="/public/static/admin/js/plugins/iCheck/icheck.min.js"></script>

    <script src="/public/static/admin/js/article.js"></script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>产品分类</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">  
                                    <div class="panel-body">
                                        <form id="formSearch" class="form-horizontal form-inline">
                                            
                                            <button onclick="window.location.href=location.href;"  class="btn btn-primary " style="float: left; margin-right:10px;"><i class="glyphicon glyphicon-refresh"></i>刷新</button>
                                            <button onclick="openYemian('/index.php/Admin/Product/kind_form','产品分类添加')" type="button" class="btn btn-primary" style="float: left; margin-right:10px;"><i class="fa fa-plus"></i>添加</button>
                                        </form>
                                    </div>
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            
                                            <table class="table table-bordered" id="list-table">
                                            <thead>
                                                <tr>
                                                  <!--  <th></th>-->
                                                    <th>ID</th>
                                                    <th>产品类型</th>
                                                    <th>显示</th> 
                                                    <th>序号</th> 
                                                    <!-- <th>添加时间</th> -->
                                                    <th>操作</th>
                                                </tr>
                                            </thead>
                                            <tbody id="ajaxList"> 
                                                <if condition="!$list">
                                                {if !$list}
                                                    <tr>
                                                        <td colspan="7" align="center">暂无数据</td>
                                                    </tr>
                                                {/if}

                                                {foreach name="cat_list" item="vo" key="k" }
                                                  <tr role="row" class="{$vo.level}" id="{$vo.level}_{$vo.kind_id}">
                                                    <td>{$vo.kind_id}</td>

                                                    <td class="sorting_1" align="left" style="padding-left:<?php echo ($vo['level'] * 4); ?>em"> 
                                                    {if $vo.is_leaf <> 1}
                                                        <span class="glyphicon glyphicon-minus btn-warning" id="icon_{$vo.level}_{$vo.kind_id}" aria-hidden="true" onclick="rowClicked(this)" ></span>&nbsp;                  
                                                    {/if}<span><a style="color:#666;" href="{:url('Home/product/category',array('kid'=>$vo['kind_id']))}" title="点击预览" target="_block">{$vo.kind_name}</a></span>
                                                    </td>

                                                    <td>
                                                        <img width="20" height="20" class="cursor" src="/public/static/admin/images/{if $vo['is_hide'] <> 1}yes.png{else /}cancel.png{/if}" onclick="changeTableVal('product_kind','kind_id','{$vo.kind_id}','is_hide',this)"/>
                                                    </td>

                                                    <td>                         
                                                      <input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="updateSort('product_kind','kind_id','{$vo.kind_id}','sort_order',this)" size="4" value="{$vo.sort_order}" />
                                                    </td>
                                                    <td style="text-align: left;">
                                                    <a class="btn btn-primary" href="javascript:;" onclick="openYemian('/index.php/Admin/Product/kind_form/act/edit/kind_id/{$vo.kind_id}','编辑产品栏目')"><i class="fa fa-pencil"></i></a>
                                                    <a class="btn btn-danger" href="javascript:void(0)" data-url="{:url('Product/categoryHandle')}" data-id="{$vo.kind_id}" onclick="articleDel('确定删除？',{$vo.kind_id},'/index.php/Admin/Product/kind_del')"><i class="fa fa-trash-o"></i></a>
                                                    </td>
                                                  </tr>
                                                {/foreach}
                                            </tbody>
                                        </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input id="handle_status" value="" hidden="hidden">
 
<script>
    // 以下是 bootstrap 自带的  js
    function rowClicked(obj){
        span = obj;

        obj = obj.parentNode.parentNode;
        console.log(obj);
        var tbl = document.getElementById("list-table");

        var lvl = parseInt(obj.className);

        var fnd = false;
      
        var sub_display = $(span).hasClass('glyphicon-minus') ? 'none' : '' ? 'block' : 'table-row' ;
        //console.log(sub_display);
        if(sub_display == 'none'){
            $(span).removeClass('glyphicon-minus btn-info');
            $(span).addClass('glyphicon-plus btn-warning');
        }else{
            $(span).removeClass('glyphicon-plus btn-info');
            $(span).addClass('glyphicon-minus btn-warning');
        }

        for (i = 0; i < tbl.rows.length; i++){
            var row = tbl.rows[i];
          
            if (row == obj){
                fnd = true;         
            }else{
                if (fnd == true){
                    var cur = parseInt(row.className);
                    var icon = 'icon_' + row.id;
                    if (cur > lvl){
                        row.style.display = sub_display;
                        if (sub_display != 'none'){
                            var iconimg = document.getElementById(icon);
                            $(iconimg).removeClass('glyphicon-plus btn-info');
                            $(iconimg).addClass('glyphicon-minus btn-warning');
                        }else{                    
                            $(iconimg).removeClass('glyphicon-minus btn-info');
                            $(iconimg).addClass('glyphicon-plus btn-warning');
                        }
                    }else{
                        fnd = false;
                        break;
                    }
              }
            }
        }

        for (i = 0; i < obj.cells[0].childNodes.length; i++){
            var imgObj = obj.cells[0].childNodes[i];
            if (imgObj.tagName == "IMG"){
                if($(imgObj).hasClass('glyphicon-plus btn-info')){
                    $(imgObj).removeClass('glyphicon-plus btn-info');
                    $(imgObj).addClass('glyphicon-minus btn-warning');
                }else{
                    $(imgObj).removeClass('glyphicon-minus btn-warning');
                    $(imgObj).addClass('glyphicon-plus btn-info');
                }
            }
        }

    }

    function articleDel(name,kind_id,url) {
        top.layer.confirm(name,{
            icon:3,
            btn:['确定','取消'],
        } , function(){
            $.ajax({
                url : url,
                type : "post",
                data : {kind_id:kind_id},
                dataType : "json",
                success:function(data){
                    if (data.status == 0) { 
                        top.layer.msg(data.message);
                    } else {
                        top.layer.msg(data.message);
                        window.location = window.location;
                    }
                }
            });
        } , function(){
            layer.close(); //再执行关闭 
        })
    }
</script>

</body>

</html>